/** file Bend.cpp
   author belot.nicolas
*/

#include "Bend.h"

namespace libtrckr {

Bend::Bend():c(1.,1024){
	elapsed = duration= speed=.0;
	ratio = 1.;
}

Bend::Bend(const Bend& b):c(b.c){
	elapsed = b.elapsed;
	duration = b.duration;
	speed = b.speed;
	ratio = b.ratio;
}

Bend::~Bend(){

}

void Bend::Tune(DynArray<double> conf){
	speed = (1. - conf[0])/conf[1];
	duration = conf[1];
	ratio = conf[0];
}

Buffer& Bend::apply(Buffer& b , int*size){
	double bratio=1.;
	if(elapsed > duration){
		bratio=ratio;
	}else{
		bratio = 1. + speed  *elapsed;
	}
	c.ratio(bratio);
	Buffer b2(*size);
	for(uint i=0;i<*size;i++){
		b2[i]=b[i];
	}
	int retsize=c.convert(b2,b);
	*size=retsize;
	elapsed+=*size;
	return b;
}

}
